﻿namespace Microsoft.AspNetCore.Http
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using Abp.Json;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.WebUtilities;
    using Newtonsoft.Json;
    using Ydm.Extensions;

    /// <summary>
    /// header的扩展
    /// </summary>
    public static class HeaderExtensions
    {
        /// <summary>
        /// 获取门店信息
        /// </summary>
        /// <param name="header">header信息</param>
        /// <returns>获取公司Cookie</returns>
        public static HeadBuInfo GetHeadStoreInfo(this IHeaderDictionary header)
        {
            var headrStoreInfo = header["BuHeadInfo"];
            if (headrStoreInfo.Count > 0)
            {
                var storeInfo = HttpUtility.UrlDecode(headrStoreInfo.ToString());
                try
                {
                    HeadBuInfo info = JsonConvert.DeserializeObject<HeadBuInfo>(storeInfo);
                    return info;
                }
                catch (Exception)
                {
                    return null;
                }

            }
            else
            {
                return null;
            }
        }
    }

    /// <summary>
    /// 获取门店信息
    /// </summary>
    public class HeadBuInfo
    {
        /// <summary>
        /// 当前公司GUID
        /// </summary>
        public Guid? BuGUID { get; set; }

        /// <summary>
        /// 当前系统的GUID
        /// </summary>
        /// <value>The application unique identifier.</value>
        /// <remarks>于大明</remarks>
        public Guid? ApplicationGUID { get; set; }

        /// <summary>
        /// 企业GUID
        /// </summary>
        public Guid? CompanyGUID { get; set; }

    }
}